$(function() {
    let loginUser = getLoginUser();
    let userName = loginUser.userName;
    $("#loginUserName").text(userName);
    console.log("userName:"+userName)
    getOrderList();
})
function getOrderList() {
    let url = "/order/selectOrdersByUserId";
    // 取出登录的用户
    let loginUser = getLoginUser();
    let userId = loginUser.userId;
    let params={
        userId:userId
    }
    httpGet(url,params,function (data) {
        renderingOrderList(data);
    })
}

function renderingOrderList(orderList) {
    let templateOrderListHtml = $("#template_ordersList").html();
    let OrderListHtml = "";
    let tempOrderListHtml;
    //遍历商品种类列表
    let count= 1;
    $.each(orderList,function (index,order) {
        let result;
        switch (order.orderStatus) {
            case 0:
                result = "未支付";
                break;
            case 1:
                result = "支付失败";
                break;
            case 2:
                result = "支付成功";
                break;
            case 3:
                result =  "发货";
            case 4:
                result =  "到货";
            case 5:
                result =  "评价";
        }
        //后台数据填充到模板
        tempOrderListHtml=templateOrderListHtml.replace(/{count}/g, count)
            .replace(/{orderId}/g,order.orderId)
            .replace(/{totalPrice}/g,order.totalPrice)
            .replace(/{integral}/g,order.integral)
            .replace(/{orderTime}/g,order.orderCreatedTime)
            .replace(/{orderAddress}/g,order.address.detail)
            .replace(/{status}/g,result);

        OrderListHtml+=tempOrderListHtml;
        count++;
    });
    count--;
    $("#orderSize").html(count)
    console.log(OrderListHtml)
    $("#tableHead").after(OrderListHtml);

}